This example uses the Name property to give a name to a newly created object, to show what objects are in a given collection, and to delete an object from a collection.
Sub NameX()
Dim dbsNorthwind As Database
Dim qdfNew As QueryDef
Dim qdfLoop As QueryDef
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
With dbsNorthwind
' Create a new permanent QueryDef object and append it
' to the QueryDefs collection.
Set qdfNew = .CreateQueryDef()
qdfNew.Name = "NewQueryDef"
qdfNew.SQL = "SELECT * FROM Employees"
.QueryDefs.Append qdfNew
' Enumerate the QueryDefs collection to display the
' names of the QueryDef objects.
Debug.Print "Names of queries in " & .Name
For Each qdfLoop In .QueryDefs
Debug.Print " " & qdfLoop.Name
Next qdfLoop
' Delete new QueryDef object because this is a
' demonstration.
.QueryDefs.Delete qdfNew.Name
.Close
End With
End Sub